import Message from './message.vue'

export default {
  // @ts-ignore
  install (Vue) {
    const VueMsg = Vue.extend(Message)
    // @ts-ignore
    let vm = null
    vm = new VueMsg()
    vm.$mount()
    document.body.appendChild(vm.$el)
    // @ts-ignore
    let timer
    // const ShowMessage = ({ message, type, time = 2000 }) => {
    //     vm.message = message
    //     vm.type = type
    //     vm.show()

    //     setTimeout(() => {
    //         // vm.hide()
    //         vm.show()
    //     }, time)
    // }
    // Vue.Message = Vue.prototype.$message = ShowMessage
    // Vue.prototype.$message = ShowMessage

    const ShowMessage = {
      // @ts-ignore
      all_message (message, type, duration) {
        // @ts-ignore
        clearTimeout(timer)
        timer = setTimeout(() => {
          // @ts-ignore
          vm.hide()
        }, duration)
        // @ts-ignore
        vm.message = message
        // @ts-ignore
        vm.type = type
        // @ts-ignore
        vm.show()
      },
      // @ts-ignore
      success (message, type, duration = 2000) {
        this.all_message(message, type, duration)
      },
      // @ts-ignore
      error (message, type, duration = 2000) {
        this.all_message(message, type, duration)
      }
    }
    // 将方法挂载全局
    Vue.prototype.$message = ShowMessage
  }
}
